/* SPU Parallel Elliptic Curve Library - Provides Elliptic Curve Cryptographic
 * functions to the Synergistic Processing Unit target platform
 *
 * Copyright (C) 2008  Michael Annichiarico (mike.gcdeveloper@gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

static __inline unsigned int poly_cmpgt(const PFIELD2M A, const PFIELD2M B)
{
  int i;
  vector unsigned int ai, bi;
  vector unsigned int gt, lt, gt_bigger, lt_bigger;
  const vector unsigned int *a = (const vector unsigned int*)A->v;
  const vector unsigned int *b = (const vector unsigned int*)B->v;

//	printf("poly_cmpgt(A,B):\n");
//	poly_printnice(A);
//	poly_printnice(B);

  for (i=MAXWORDS-1; i>=0; --i) {
    ai = a[i];
    bi = b[i];

    gt = spu_gather(spu_cmpgt(ai, bi));
    lt = spu_gather(spu_cmpgt(bi, ai));

    gt_bigger = spu_cmpgt(gt, lt);
    lt_bigger = spu_cmpgt(lt, gt);

    if (spu_extract(spu_or(gt_bigger, lt_bigger), 0)) {
//	printf("poly_cmpgt returning %d\n",spu_extract(gt_bigger,0));
      return (spu_extract(gt_bigger, 0));
    }
  }
	printf("poly_cmpeq returning 0\n");
  return (0);
}
